#!/usr/bin/env python3

import re

import common
from shell_helpers import LF

class Main(common.LkmcCliFunction):
    def __init__(self):
        super().__init__(
            defaults = {
                'print_time': False,
            },
            description='''\
https://github.com/cirosantilli/linux-kernel-module-cheat#build-the-documentation
''',
        )

    def timed_main(self):
        self.sh.run_cmd(
            [
                'asciidoctor', LF,
                '-o', self.env['readme_out'], LF,
                '-v', self.env['readme'], LF,
            ],
            out_file=self.env['build_doc_log'],
        )
        error_re = re.compile('^asciidoctor: WARNING: ')
        exit_status = 0
        with open(self.env['build_doc_log']) as f:
            for line in f:
                if error_re.search(line):
                    exit_status = 1
                    break
        return exit_status

if __name__ == '__main__':
    Main().cli()
